package cn.icanci.design.builder.prototypepattern.demo04;

import java.io.*;
import java.util.List;

/**
 * @author icanci
 * @date Created in 2021/07/15 22:43
 * @version 1.0
 */
public class ClassD implements Cloneable, Serializable {
    private String       id;
    private List<String> address;

    @Override
    protected ClassD clone() throws CloneNotSupportedException {
        return (ClassD) super.clone();
    }

    public ClassD deepClone() throws IOException, ClassNotFoundException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(this);
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        return (ClassD) ois.readObject();
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("ClassA{");
        sb.append("id='").append(id).append('\'');
        sb.append(", address=").append(address);
        sb.append('}');
        return sb.toString();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public List<String> getAddress() {
        return address;
    }

    public void setAddress(List<String> address) {
        this.address = address;
    }
}
